package org.yly.game.rpggame.domain.model;


public class CustomProperty {

	protected PropertyName name;
	protected int initValue;  // 初始值
	protected int addValue; // 增加值
	protected int subValue; //  减少值
	

	public CustomProperty(PropertyName name, int initValue) {
		super();
		this.name = name;
		this.initValue = initValue;
	}

	public PropertyName getName() {
		return name;
	}

	/**
	 * 获得属性值
	 * @return
	 */
	public int getValue() {
		int value = initValue + addValue - subValue;
		return value < 0 ? 0 : value;
	}
	/**
	 * 同一类属性
	 * @param property
	 * @return
	 */
	public boolean equalsName(CustomProperty property) {
		return this.name == property.getName();
	}
	
	/**
	 * 属性相加
	 * 
	 * @return
	 */
	public void add(CustomProperty property) {
		if (this.equalsName(property)) {
			this.addValue += property.getValue();
		}
	}
	
	/**
	 * 属性减
	 * 
	 * @return
	 */
	public void sub(CustomProperty property) {
		if (this.equalsName(property)) {
			this.subValue += property.getValue();
		}
	}
	
	public void clearSubValue(){
		this.subValue = 0;
	}
	
}
